package NewCoder;

public class BM18 {
    public boolean Find(int target, int [][] array) {
        int n=array.length;
        int m=array[0].length;
        if(n==0 && m==0) return false;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                int l=0;
                int r=m-1;
                while(l<=r){
                    int mid=(r-l)/2+l;
                    if(array[i][mid]<target){
                        l=mid+1;
                    }else if(array[i][mid]>target){
                        r=mid-1;
                    }else{
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
